#include <stdio.h>
#include <string.h>
double get_crypto_price(char * ticker)
{
	// Run command
	char command_buffer[64];
	snprintf(command_buffer, 64, "curl -s https://api.btcmarkets.net/v3/markets/%s/ticker", ticker);
	FILE * fp = popen(command_buffer, "r");
	if (fp == NULL)
	{
		return -1;
	}

	// Get price
	char result_buffer[512];
	if ( fgets(result_buffer, 512, fp) == NULL )
	{
		return -1;
	}
	double price;
	char * start = strstr(result_buffer, "bestAsk") + strlen("bestAsk\":\"");
	if (start == NULL)
	{
		return -1;
	}
	sscanf(start, "%lf", &price);

	return price;
}
